﻿var imageLoaderPage = 1;

function ShowPreloader() {
    $('.preloader > img').css('display', 'block');
}
function HidePreloader() {
    $('.preloader > img').css('display', 'none');
}

function GetNextImages() {
    $.post("/Home/GetNextImages",
               {
                   id: imageLoaderPage + 1
               },
           function (imagesList) {
               if (imagesList !== undefined) {
                   HidePreloader();
                   $('#huge-content-wrapper ul').append(imagesList);
                   imageLoaderPage += 1;
               }
           });
}

$(function () {
    $(document).scroll(function () {
        var w = $(window);
        var d = $(document);

        var sum = w.scrollTop() + w.height();
        if (d.height() == sum || d.height() - 1 == sum) {
            ShowPreloader();
            GetNextImages();
        }
    });
})